<%@ page import="com.oval.util.JspHelper" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>
<%@ page import="com.oval.util.*" %>
<%@ page contentType = "text/html;charset=UTF-8" %>
<%
  String  	flag = "";
  String	editforps = "";
  String[] arrId = request.getParameterValues("checkedIds");  
  UserInfo a_user = new UserInfo(session.getId(),
                                 UserInfo.CENTER_APP,
                                 new Integer(-1),
                                 new Integer(-1),
                                 "CONSOLE"
                                 );
 
  if(arrId != null && request.getParameter("actionname") != null && request.getParameter("actionname").equals("delete"))
  {
    String codes = "'-1'";
    for(int j=0;j<arrId.length;j++)
    {
      codes += ",'";
      codes += arrId[j] + "'";
    }
    String whereclause = " and ovalmessage.messageid in (" + codes + ")";
    
    OvalDeleteAPI oda = new OvalDeleteAPI();
    oda.setBI(a_user,new Long(-1000),new Integer(0));
    HashMap fm = oda.deleteData("ovovalmessage",whereclause,null,null);
    if(!(((Boolean)(fm.get("IsSuccess"))).booleanValue()))
      flag = "Delete Message Failed!";
    else
      flag = "Delete Message Successfully!";           
  } else if(request.getParameter("actionname") != null && request.getParameter("actionname").equals("save")){     
    String messagecode = request.getParameter("messagecode");
    String messagetype = request.getParameter("messagetype");
    String messagename = request.getParameter("messagename");
    String module = request.getParameter("module");
    String messagedesccn = OvalEncode.convertEncode(request.getParameter("messagedesccn"),"iso-8859-1","utf-8");
    String messagedescen = request.getParameter("messagedescen");
    String messagedescjp = OvalEncode.convertEncode(request.getParameter("messagedescjp"),"iso-8859-1","utf-8");
    HashMap hm1 = new HashMap();
    hm1.put("app","DRP");
    hm1.put("messagecode",messagecode);
    hm1.put("messagetype",messagetype);
    hm1.put("messagename",messagename);
    if(module != null)
      hm1.put("module",module);
    hm1.put("messagedesc",messagedesccn);
    hm1.put("languagecode","cn");
    HashMap hm2 = new HashMap();
    hm2.put("app","DRP");
    hm2.put("messagecode",messagecode);
    hm2.put("messagetype",messagetype);
    hm2.put("messagename",messagename);
    if(module != null)
      hm2.put("module",module);
    hm2.put("messagedesc",messagedescen);
    hm2.put("languagecode","en");
    HashMap hm3 = new HashMap();
    hm3.put("app","DRP");
    hm3.put("messagecode",messagecode);
    hm3.put("messagetype",messagetype);
    hm3.put("messagename",messagename);
    if(module != null)
      hm3.put("module",module);
    hm3.put("messagedesc",messagedescjp);
    hm3.put("languagecode","jp");
    OvalSaveAPI osa = new OvalSaveAPI();
    osa.setBI(a_user,new Long(-1000),new Integer(0));
    OvalCustomMessage message1 = new OvalCustomMessage(hm1);
    OvalCustomMessage message2 = new OvalCustomMessage(hm2);
    OvalCustomMessage message3 = new OvalCustomMessage(hm3);
    String flag1 = osa.saveData(hm1,"ovovalmessage");
    if(flag1.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message1.getMessageIndex(),message1);
      flag1 = "Successfully!";
    }
    String flag2 = osa.saveData(hm2,"ovovalmessage");
    if(flag2.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message2.getMessageIndex(),message2);
      flag2 = "Successfully!";
    }
    String flag3 = osa.saveData(hm3,"ovovalmessage");
    if(flag3.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message3.getMessageIndex(),message3);
      flag3 = "Successfully!";
    }
    flag = "Save Message(CN):" + flag1 + "<br>Save Message(EN):" + flag2 + "<br>Save Message(JP):" + flag3;  
  } else if(request.getParameter("actionname") != null && request.getParameter("actionname").equals("edit")){
    String messagecode = request.getParameter("messagecode");
    String messagetype = request.getParameter("messagetype");
    String messagename = request.getParameter("messagename");
    String module = request.getParameter("module");
   String messagedesccn = OvalEncode.convertEncode(request.getParameter("messagedesccn"),"iso-8859-1","utf-8");
    String messagedescen = request.getParameter("messagedescen");
    String messagedescjp = OvalEncode.convertEncode(request.getParameter("messagedescjp"),"iso-8859-1","utf-8");
    String enid = request.getParameter("edit_enid");
    String cnid = request.getParameter("edit_cnid");
    String jpid = request.getParameter("edit_jpid");
    Integer enidInt = new Integer(enid);
    Integer cnidInt = new Integer(cnid);
    Integer jpidInt = new Integer(jpid);
    HashMap hm1 = new HashMap();
    hm1.put("messageid", cnidInt);
    hm1.put("app","DRP");
    hm1.put("messagecode",messagecode);
    hm1.put("messagetype",messagetype);
    hm1.put("messagename",messagename);
    if(module != null)
      hm1.put("module",module);
    hm1.put("messagedesc",messagedesccn);
    hm1.put("languagecode","cn");
    HashMap hm2 = new HashMap();
    hm2.put("messageid", enidInt);
    hm2.put("app","DRP");
    hm2.put("messagecode",messagecode);
    hm2.put("messagetype",messagetype);
    hm2.put("messagename",messagename);
    if(module != null)
      hm2.put("module",module);
    hm2.put("messagedesc",messagedescen);
    hm2.put("languagecode","en");
    HashMap hm3 = new HashMap();
    hm3.put("messageid", jpidInt);
    hm3.put("app","DRP");
    hm3.put("messagecode",messagecode);
    hm3.put("messagetype",messagetype);
    hm3.put("messagename",messagename);
    if(module != null)
      hm2.put("module",module);
    hm3.put("messagedesc",messagedescjp);
    hm3.put("languagecode","jp");
    OvalSaveAPI osa = new OvalSaveAPI();
    osa.setBI(a_user,new Long(-1000),new Integer(0));
    OvalCustomMessage message1 = new OvalCustomMessage(hm1);
    OvalCustomMessage message2 = new OvalCustomMessage(hm2);
    OvalCustomMessage message3 = new OvalCustomMessage(hm3);
    String flag1 = osa.saveData(hm1,"ovovalmessage");
    if(flag1.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message1.getMessageIndex(),message1);
      flag1 = "Successfully!";
    }
    String flag2 = osa.saveData(hm2,"ovovalmessage");
    if(flag2.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message2.getMessageIndex(),message2);
      flag2 = "Successfully!";
    }
    String flag3 = osa.saveData(hm3,"ovovalmessage");
    if(flag3.equals("1"))
    {
      OvalCustomMessageEngine.addMessage(message3.getMessageIndex(),message3);
      flag3 = "Successfully!";
    }
    flag = "Edit Message(CN):" + flag1 + "<br>Edit Message(EN):" + flag2 + "<br>Edit Message(JP):" + flag3;  
    
    editforps = request.getParameter("editforps");
    if(editforps==null)
      editforps = "";
}

%>


<html>
<head>
<title>e-manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="../css/chinese/script.js"></script>
<script language="JavaScript">
function page_back()
{
  self.location.href = "MessageSummary.jsp";
}

</script>
</head>
<body>
<form name="frm">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
  <tr> 
    <td class="td_title_bg">
     <div align="center">
       Operate Message
     </div>     
    </td>
  </tr>
  <tr class="td_bg_row"> 
    <td class="text">
     <div align="center">
       <%=JspHelper.filterNull( flag )%>
     </div>
    </td>
  </tr>
  <tr> 
    <td class="td_title_bg">
     <div align="center">
     <%if(editforps.equalsIgnoreCase("Y")){%>
       <input type="button" name="BACK" value="BACK" onclick="javascript:history.back()">
       <input type="button" name="BACK" value="CANCEL" onclick="javascript:window.close()">
     <%}else{%>
       <input type="button" name="BACK" value="BACK" onclick="javascript:page_back()">
     <%}%>
     </div>     
    </td>
  </tr>
</table>
</form>
</body>
</html>

